package com.ruoyi.lol;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import java.net.URI;

public class MyWebSocketClient extends WebSocketClient {

    public MyWebSocketClient(URI serverUri) {
        super(serverUri);
    }

    @Override
    public void onOpen(ServerHandshake handShake) {
        System.out.println("连接已建立");
        // 连接成功后可以发送初始消息
        send("Hello, Server!");
    }

    @Override
    public void onMessage(String message) {
        System.out.println("收到消息: " + message);
        // 根据需要处理接收到的消息
    }

    @Override
    public void onClose(int code, String reason, boolean remote) {
        System.out.println("连接已关闭，代码: " + code + ", 原因: " + reason);
    }

    @Override
    public void onError(Exception ex) {
        System.out.println("发生错误: " + ex.getMessage());
        ex.printStackTrace();
    }
}
